<?php
require_once dirname(__FILE__).'/../lib/sony_category_assets_addGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/sony_category_assets_addGeneratorHelper.class.php';

/**
 * sony_category_assets_add actions.
 *
 * @package    astolfo
 * @subpackage sony_category_assets_add
 * @author     Emerson Estrella
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class sony_category_assets_addActions extends autoSony_category_assets_addActions
{

	public function executeIndex(sfWebRequest $request)
	{
		$this->setLayout("layout_min");
	
		echo ">>>".$request->getParameter('category_id');
		$this->filters = $this->configuration->getFilterForm($this->getFilters());
		
		if($request->getParameter('category_id')>0)
		$this->category = Doctrine::getTable('SonyCategory')->find($request->getParameter('category_id'));
	
		// sorting
		if ($request->getParameter('sort') && $this->isValidSortColumn($request->getParameter('sort')))
		{
			$this->setSort(array($request->getParameter('sort'), $request->getParameter('sort_type')));
		}
	
		// pager
		if ($request->getParameter('page'))
		{
			$this->setPage($request->getParameter('page'));
		}
	
		$this->pager = $this->getPager();
		$this->sort = $this->getSort();
	}
	
	
	public function executeIndex4(sfWebRequest $request)
	{
		$this->query = Doctrine_Query::create()
			->select('a.*')
			->from('SonyAsset a')
			->execute();
	
		$this->filters = $this->configuration->getFilterForm($this->getFilters());
	
		if($request->getParameter('category_id')>0)
			$this->category = Doctrine::getTable('SonyCategory')->find($request->getParameter('category_id'));
		// sorting
		if ($request->getParameter('sort') && $this->isValidSortColumn($request->getParameter('sort'))) {
			$this->setSort(array($request->getParameter('sort'), $request->getParameter('sort_type')));
		}
		// pager
		if ($request->getParameter('page')) {
			$this->setPage($request->getParameter('page'));
		}
		$this->pager = $this->getPager();
		$this->sort = $this->getSort();
	}
	
	
	public function executeIndex3(sfWebRequest $request)
	{
		parent::executeIndex($request);
		$this->setLayout("layout_min");
		$this->category = Doctrine::getTable('SonyCategory')->find($request->getParameter('category_id'));
		$this->filters = $this->configuration->getFilterForm($this->getFilters());
		$this->query = Doctrine_Query::create()
			->select('a.*')
			->from('SonyAsset a')
			->where('a.is_active = 1')
			->orderBy('a.created_at');
		$this->pager = $this->getPager();
	}
	
	public function executeIndex2(sfWebRequest $request)
	{
		$this->setLayout("layout_min");
		$this->category = Doctrine::getTable('Section')->find($request->getParameter('category_id'));
		$this->filters = $this->configuration->getFilterForm($this->getFilters());
		parent::executeIndex($request);
		$this->query = Doctrine_Query::create()
			->select('a.*')
			->from('SonyAsset a')
			->where('a.is_active = 1')
			->orderBy('a.created_at');
		$this->pager = $this->getPager();
	}
	
	/*
	public function executeAll(sfWebRequest $request){
		parent::executeIndex($request);
		$this->filters = $this->configuration->getFilterForm($this->getFilters());
		$this->query = Doctrine_Query::create()
			->select('a.*')
			->from('SonyAsset a')
			->where('a.id = sa.asset_id')
			->orderBy('created_at desc');
		$this->pager = $this->getPager();
	}
	*/

	protected function getPager()
	{
		$pager = $this->configuration->getPager('SonyAsset');
		$pager->setQuery($this->query);
		$pager->setPage($this->getPage());
		$pager->init();
		return $pager;
	}
	/*
	public function executeBatchSave(sfWebRequest $request){
		$ids = $request->getParameter('ids');
		foreach($ids as $id){
			$categoryAsset = Doctrine::getTable('SonyCategoryAsset')->findBySonyCategoryIdAndSonyAssetId($request->getParameter('cateogry_id'), $id);
			if(!$categoryAsset)
				$categoryAsset = new SectionAsset();
			$categoryAsset->sony_category_id = $request->getParameter('category_id');
			$categoryAsset->sony_asset_id = $id;
		  $categoryAsset->save();
		}
		die('<script>parent.updateCategoryAssets('.$request->getParameter('category_id').');</script>');
	}
	*/
	
}
